using System;
using System.Collections.Generic;
using System.Text;
using ACS.Compiler.Tables;
using ACS.Compiler.Tables.Modes;
using ACS.Compiler.Tree;
using antlr;

namespace ACS.Compiler.Util
{
    public class Logger
    {
        private static Logger _instance;

            
        public static Logger Instance
        {
            get
            {
                return _instance ?? (_instance = new Logger());
            }
        }

        public void TraceError(string error)
        {
            throw new Exception(error);
        }

        public void TraceError(string error, TreeBase tree)
        {
            IToken tok = tree.FindToken();
            if (tok != null)
            {
                throw new Exception(error + " line:" + tok.getLine() + " col:" + tok.getColumn());
            } else
            {
                throw new Exception(error);
            }
        }

        public void TraceModesNotEquals(Mode m1, Mode m2, TreeBase tree)
        {
            string leftString = m1 == null? "unknown": m1.ToString();
            string rightString = m2 == null? "unknown": m2.ToString();
            Instance.TraceError(
                String.Format("Mode not equals.\n  Mode1 = {0} \n  Mode2 = {1}\n",
                leftString, rightString), tree);
        }

        public void TraceWrongMode(Mode m1, TreeBase tree)
        {
            string leftString = m1 == null? "unknown": m1.ToString();
            Instance.TraceError(
                String.Format("Wrong mode:\n  Mode1 = {0}\n",
                leftString), tree);
        }
    }
}
